﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Admin.Host.Core.Authentication/AccessTokenStore 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       AccessTokenStore
* 创建时间：  2025/5/24 11:56:02
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using SSPivot.Authorization.AccessToken;
using SSPivot.Common.Interface;

namespace SSPivot.Admin.Host.Core.Authentication
{
    public class AccessTokenStore : IAccessTokenStore, ITransientDependency
    {
        //public IAccessTokenService AccessTokenService { get; set; }
        //public IAdminUserService AdminUserService { get; set; }
        //public IAdminRoleService AdminRoleService { get; set; }

        public async Task<AccessTokenValidatedResult> ValidateAsync(string accessToken)
        {
            var result = new AccessTokenValidatedResult();
            //var decryptToken = AccessTokenService.DecryptAccessToken(accessToken);
            //if (decryptToken.UserId.HasValue)
            //{
            //    //验证
            //    var validated = await AccessTokenService.ValidateAccessTokenAsync(decryptToken.UserId.Value, decryptToken.AccessToken);
            //    if (validated)
            //    {
            //        var admin = await AdminUserService.GetAsync(decryptToken.UserId.Value);
            //        if (admin != null)
            //        {
            //            var identity = new ClaimsIdentity(AccessTokenConsts.AuthenticationScheme);

            //            identity.AddClaim(new Claim(LHHTClaimTypes.UserName, admin.LoginName));
            //            identity.AddClaim(new Claim(LHHTClaimTypes.Name, admin.NickName));
            //            identity.AddClaim(new Claim(LHHTClaimTypes.UserId, admin.Id.ToString()));
            //            identity.AddClaim(new Claim(LHHTClaimTypes.PhoneNumber, admin.Phone));

            //            if (admin.UserRoleScope != null && admin.UserRoleScope.Count > 0)
            //            {
            //                identity.AddClaim(new Claim(LHHTClaimTypes.Role, admin.UserRoleScope.SerializeJson()));
            //                var roleIds = admin.UserRoleScope;
            //                var roles = (await AdminRoleService.GetAllAsync()).Where(e => roleIds.Contains(e.Id)).Select(e => e.RoleMenuScope).ToList();
            //                if (roles != null && roles.Count > 0)
            //                {
            //                    var roleMenus = new List<long>();
            //                    foreach (var item in roles)
            //                    {
            //                        roleMenus.AddRange(item);
            //                    }
            //                    roleMenus = roleMenus.Distinct().ToList();
            //                    identity.AddClaim(new Claim(LHHTClaimTypes.RoleScope, roleMenus.SerializeJson()));
            //                }
            //            }
            //            var principal = new ClaimsPrincipal(identity);
            //            result.Validated = true;
            //            result.Result = principal;
            //        }
            //    }
            //}
            return result;
        }
    }
}

